<?php
namespace app\model;
use think\model;
use think\facade\Db;

class ArticleCol extends Model{

    protected $table = "user_articlecol";


    // 插入
    public function insertArticleCol($data,$uid,$id){
        $at = ArticleCol::Create([
            "userId"=>$uid,
            "atId"=>$id,
            "springboot"=>$data["springboot"],
            "ssm"=>$data["ssm"],
            "Linux"=>$data["Linux"],
            "MySql"=>$data["MySql"],
            "ThinkPHP"=>$data["ThinkPHP"],
            "Redis"=>$data["Redis"],
        ]);
        return $at;
    }


    // 保存
    public function saveArticleCol($data,$uid,$id){
        foreach ($data as $key=>$value){
            $artCol = new ArticleCol();
            $artCol->updateArticleCol($uid,$id,$key,$value);
        }
    }

    public function updateArticleCol($uid,$id,$key,$flag){
        ArticleCol::update([
            "$key"=>"$flag"
        ],[
            'atId'=>"$id",
            'userId'=>"$uid"
        ]);
    }

    // 查询单篇文章的信息
    function queryArtCol($id,$uid){
        $artCol = ArticleCol::where('atId',$id)->where('userId',$uid)->find();
        return $artCol;
    }

    function delAtById($id){
        Db::table('user_articlecol')->where('atId',$id)->delete();
    }
}